package auctionhaus

class LoginController {

     def login() {
         if (!session.customer)  {
             if (request.get){
                 render view: 'index'
                 return
             }
            Customer customer =  Customer.findByEmailAddressAndPassword(params.email, params.password)
            if (customer) {
                session.customer = customer
                flash.message = "Successfully logged in."
                redirect(controller: 'listing', action: 'list')
            } else {
                flash.message = "Invalid login."
                render(view: 'index')
            }
        }
        else
        {
            redirect(controller: 'listing', action: 'list')
        }
    }

    def logout() {
        flash.message = "Successfully logged out."
        session.customer = null
        redirect(controller: 'listing', action: 'list')
    }
}
